/*
 * $Id$
 *
 * Copyright 2008 HingeSoftware. All rights reserved.
 */
package com.crm.web.page;

import org.apache.tapestry.html.BasePage;

import java.util.List;
import java.util.ArrayList;

import com.javaforge.tapestry.spring.annotations.InjectSpring;
import com.crm.service.ICustomerService;
import com.crm.service.IContactService;
import com.crm.service.IProcessService;
import com.crm.model.SysLog;
import com.crm.model.Contact;
import com.crm.model.Customer;

/**
 * @author <a href="mailto:huang.huang@hingesoftware.com">HuangHuang</a>
 * @version $Id$
 */
public abstract class SysDelHis extends BasePage {

    @InjectSpring("customerService")
    public abstract ICustomerService getCustomerServ();

    @InjectSpring("contactService")
    public abstract IContactService getContactServ();

    @InjectSpring("processService")
    public abstract IProcessService getProcessServ();

    private String uid;

    private Contact contact;

    private Customer customer;

    private String flag;

    private int count;

    public Contact getContact() {
        return contact;
    }

    public Customer getCustomer() {
        return customer;
    }

    public String getFlag() {
        return flag;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getRecordCount() {
        return "共" + count + "条记录";
    }

    public List getDelHis() {
        List list;

        if (null == flag || SysLog.T_CUST.equals(flag)) {
            list = getCustomerServ().getRecycleCust(uid);
        } else if (SysLog.T_CONT.equals(flag)) {
            list = getContactServ().getRecycleCont(customer.getId());
        } else if (SysLog.T_PROC.equals(flag)) {
            list = getProcessServ().getRecycleProc(null==contact?"":contact.getId());
        } else {
            list = new ArrayList();
        }

        count = list.size();
        return list;
    }

    public String onShowContacts(Customer customer){
        flag = SysLog.T_CONT;
        this.customer = customer;
        return getPageName();
    }

    public String onShowProcesses(Contact contact){
        flag = SysLog.T_PROC;
        this.contact = contact;
        return getPageName();
    }

}
